package com.ikangtai.shecare.common.baseView.pickerDialog.recordPickerDialog;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.ikangtai.shecare.R;

/**
 * Created by Administrator on 2016/1/23.
 */
public class TemperaturePickerDialog extends AlertDialog implements
        DialogInterface.OnClickListener {
    private TemperaturePicker mTemperaturePicker;
    private int degree = 36;
    private int minute = 50;
    private OnTemperatureSetListener mOnTemperatureSetListener;
    @SuppressWarnings("deprecation")
    public TemperaturePickerDialog(Context context,String temper) {
        super(context);
        mTemperaturePicker = new TemperaturePicker(context,temper);
        degree = Integer.valueOf(temper.substring(0,2));
        minute = Integer.valueOf(temper.substring(3));
        setView(mTemperaturePicker);
        /*
         *实现接口，实现里面的方法
         */
        mTemperaturePicker
                .setOnTemperatureChangedListener(new TemperaturePicker.OnTemperatureChangedListener() {
                    @Override
                    public void onTemperatureChanged(TemperaturePicker view, int hour, int minutes) {
                        degree = hour;
                        minute = minutes;
                    }
                });


        setButton(context.getString(R.string.setting), this);
        setButton2(context.getString(R.string.cancel), (OnClickListener) null);
        setTitle(context.getString(R.string.bbt_set));
    }
    /*
     *接口回調
     *控件 秒数
     */
    public interface OnTemperatureSetListener {
        void OnTemperatureSet(AlertDialog dialog, String temperature);
    }

    /*
     * 对外公开方法让Activity实现
     */
    public void setOnTemperatureeSetListener(OnTemperatureSetListener callBack) {
        mOnTemperatureSetListener = callBack;
    }

    public void onClick(DialogInterface arg0, int arg1) {
        if (mOnTemperatureSetListener != null) {
            mOnTemperatureSetListener.OnTemperatureSet(this, getSelectDegree(degree, minute));
        }
    }

    private String getSelectDegree(int degree, int minute){

        String hourStr = String.valueOf(degree);
        if (degree < 10) {
            hourStr = "0" + hourStr;
        }
        String minuteStr = String.valueOf(minute);
        if (minute < 10) {
            minuteStr = "0" + minuteStr;
        }
        return hourStr + "." + minuteStr  + "℃";
    }
}
